package com.jiajia.study.chapter04;

import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.EventLoop;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.Promise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;

public class NettyPromise {
    private static final Logger log = LoggerFactory.getLogger(NettyPromise.class);

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        DefaultEventLoopGroup defaultEventLoopGroup = new DefaultEventLoopGroup();
        EventLoop next = defaultEventLoopGroup.next();

        Promise<Integer> promise = new DefaultPromise<>(next);

        Thread thread = new Thread(() -> {
            log.debug("执行了......................");
            promise.setSuccess(10);
        });
        thread.start();

        // 同步阻塞
//        Integer result = promise.get();
//
//        log.debug("result is : {}",result);

        promise.addListener(future -> {
            Integer resultData = promise.get();
            log.debug("result data is : {}",resultData);

        });

        log.debug("执行完成");
    }


}
